﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SIPO.master" AutoEventWireup="false"
    CodeFile="recObjectionList.aspx.cs" Inherits="SIPO.Web.Lists.Transaction.recObjectionList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="body" runat="Server">

    <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
    <div>
        <button id="btnAdd" type="button" onclick="OpenForm('add');">
            Tambah</button>
        <button id="btnEdit" type="button" onclick="OpenForm('edit');">
            Ubah</button>
        <button id="btnDelete" type="button" onclick="OpenForm('delete');">
            Hapus</button>
    </div>
    <br />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll">
    </div>
    <div id="dialog" title="Default dialog">
    </div>
    <script type="text/javascript">

        $("#btnAdd").button({ icons: { primary: "ui-icon-plus"} });
        $("#btnEdit").button({ icons: { primary: "ui-icon-pencil"} });
        $("#btnDelete").button({ icons: { primary: "ui-icon-trash"} });
    
    </script>
    <script type="text/javascript">

        var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Transaction/recObjectionHandler.ashx") %>';
        $('#table').jqGrid({
            url: handlerUrl + '?method=getdata',
            datatype: 'json',
            colNames: ['ObjectionID', 'Debitur', 'No. Permohonan', 'Tanggal Permohonan', 'No. Sanksi', 'Tanggal Sanksi', 'Jumlah Sanksi (Rp)', 'Catatan', 'Status', 'Lampiran'],
            colModel: [
                    { name: 'ObjectionID', hidden: true, index: 'ObjectionID', align: 'left', width: 100 },
                    { name: 'recDebtor.DebtorName', index: 'recDebtor.DebtorName', align: 'left', width: 100, searchoptions: { sopt: ['eq', 'cn']} },
                    { name: 'ObjectionNo', index: 'ObjectionNo', align: 'left', width: 100, searchoptions: { sopt: ['eq', 'cn']} },
                    { name: 'ObjectionDate', index: 'ObjectionDate', align: 'left', width: 100, searchoptions: { sopt: ['eq', 'cn']} , formatter: 'date', formatoptions: { newformat: 'd M Y'} },
                    { name: 'SanctionNo', index: 'SanctionNo', align: 'left', width: 100, searchoptions: { sopt: ['eq', 'cn']} },
                    { name: 'SanctionDate', index: 'SanctionDate', align: 'left', width: 150, searchoptions: { sopt: ['eq', 'cn']} , formatter: 'date', formatoptions: { newformat: 'd M Y'} },
                    { name: 'SanctionValue', index: 'SanctionValue', formatter: 'number', searchtype: 'number', align: 'Right', width: 150 },
                    { name: 'ObjectionNote', index: 'ObjectionNote', align: 'Left', width: 100, searchoptions: { sopt: ['eq', 'cn']} },
                    { name: 'TransStatus', index: 'TransStatus', align: 'Left', width: 100 },
                    { name: 'ObjectionID', index: 'ObjectionID', align: 'center', width: 100, search: false, formatter: returnMyLink }
           	],
            rowNum: 10,
            id: 'ObjectionID',
            multiselect: true,
            rowList: [5, 10, 15, 20],
            pager: '#pager',
            sortname: 'recObjection.CreatedDate',
            sortorder: "desc",
            viewrecords: true,
            jsonReader: { repeatitems: false },
            width: 1250,
            height: '100%',
            caption: 'Permohonan Keberatan',
            ajaxGridOptions: { cache: false }
        });
        $("#table").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, searchtext: 'Search', refreshtext: 'Refresh' },
        {}, {}, {}, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true });


        function returnMyLink(cellValue, options, rowdata) {

            return "<a href='#' onclick='downloadfile(" + cellValue + ")'>download</a>";
        }

        function downloadfile(cellValue) {
        
            var obj = new Object();
            obj.ObjectionID = encodeURIComponent(cellValue);
            jsonData = JSON.stringify(obj);

            var handlerUrl = '<%= ResolveUrl("~/ajaxhandler/loaddata/downloadhandler.ashx") %>';

            $.ajax({
                type: 'POST',
                url: handlerUrl + "?method=checkfileobjection",
                contentType: 'application/json',
                dataType: 'json',
                data: jsonData,
                success: function (data) {
                    if (data.IsSuccess) {
                        var win = window.open(handlerUrl + '?method=downloadobjection&ObjectionID=' + cellValue, '_blank');
                        win.focus();
                    }
                    else {
                        alert(data.Message);
                    }
                },
                error: function (response) {
                    alert('Error saat download file!');
                }
            });

        }

        
        function OpenForm(ctl) {

            var formUrl = '<%= ResolveUrl("~/forms/Transaction/recObjectionForm.aspx") %>';
            var grid = $('#table');
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
            $.each(selIds, function () {
                selText.push(grid.jqGrid('getCell', this, 'ObjectionID'));
            });

            if (ctl == 'edit') {
                if (selIds.length == 0) {
                    alert('Pilih data yang mau di ubah !');
                }
                else if (selIds.length > 1) {
                    alert('Pilih satu record untuk ubah data.');
                }
                else {
                    $('#dialog').load(formUrl + '?id=' + selText + '&menuId=' + '<%= base.MenuID %>').dialog({ autoOpen: false, modal: true, width: 500, height:430, title: 'Ubah Permohonan Keberatan',
                        close: function (event, ui) {
                            $('#dialog').empty().dialog('destroy');
                        }
                    });
                    $("#dialog").dialog('open');
                }
            }
            else if (ctl == 'add') {
                $('#dialog').load(formUrl + '?menuId=' + '<%= base.MenuID %>').dialog({ autoOpen: false, modal: true, width: 500, height:430, title: 'Tambah Permohonan Keberatan',
                    close: function (event, ui) {
                        $('#dialog').empty().dialog('destroy');
                    }
                });
                $("#dialog").dialog('open');
            }
            else {
                if (selIds.length == 0)
                    alert('Pilih data yang mau di hapus !');
                else {
                    var result = window.confirm('Benar data akan di hapus ?');
                    if (result) {

                        var objrecObjection = new Object();
                        objrecObjection.ObjectionID = encodeURIComponent(selText);
                        jsonData = JSON.stringify(objrecObjection);

                        CallAjax('<%= ResolveUrl("~/ajaxhandler/transaction/recObjectionHandler.ashx") %>', "?method=delete", jsonData);
                        
                        setTimeout("$('#table').trigger('reloadGrid');", 3000);
                    }
                }

            }
        }
        
    </script>
</asp:Content>
